package com.hcy.app.data.dao

import androidx.room.Dao
import androidx.room.Database
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.Insert
import androidx.room.PrimaryKey
import androidx.room.Query
import androidx.room.RoomDatabase

@Entity(tableName = "tb_songs")//定义数据表的名称
data class Song(
    @PrimaryKey(autoGenerate = true)
    var id: Long = 0L,
    var title: String="",// 歌曲名称
    var artist: String="",// 艺术家
    var filePath: String="",// 文件路径
    var imgPath: String="",// 专辑图片路径
    var isFavorite: Boolean=false,// 是否最爱
    var label: String="", // 标签
    var createAt: Long=0L, // 创建时间

    @Ignore//则不会作为表字段存入
    var isSelected: Boolean=false
)

// dao层
@Dao
interface SongDao {
    @Query("select * from tb_songs")
    fun findAll(): List<Song>

    @Query("delete from tb_songs where filePath = :filePath")
    suspend fun delete(filePath: String)

    @Insert(Song::class)
    fun insert(s: Song)
}
